package com.sxbbc.plat.controller.jz;

import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.servlet.ModelAndView;

import com.function.common.GetRest;
import com.function.common.RestResponse;
import com.sxbbc.plat.common.StatisMapping;
import com.sxbbc.plat.service.StatisService;

/**
 * 平台图表统计 控制层
 * @author xiaoky
 * @date 2019-05-13
 */
@Controller
public class StatisController {
	@Autowired
	private StatisService statisService;
	
	/**
	 * 订单、退款金额统计页面
	 * @return
	 * @author xiaoky
	 */
	@RequestMapping(value = StatisMapping.SHOW_REFUND_MONEY_STATIS)
	public ModelAndView showRefundMoneyStatis () {
		ModelAndView view = new ModelAndView(StatisMapping.SHOW_REFUND_MONEY_STATIS);
		return view;
	}
	
	/**
	 * 订单&退款金额数据
	 * @param type 类型——day,work,month
	 * @return
	 */
	@RequestMapping(value = StatisMapping.QUERY_REFUND_MONEY_STATIS)
	@ResponseBody
	public RestResponse queryRefundMoneyStatis (String type) {
		Map<String, Object> map = statisService.queryRefundMoneyStatis(type);
		return GetRest.getSuccess("SUCCESS", map);
	}
	
	/**
	 * 用户统计
	 * @return
	 * @author xiaoky
	 */
	@RequestMapping(value = StatisMapping.SHOW_CUSTOMER_STATIS)
	public ModelAndView showCustomerStatis () {
		ModelAndView view = new ModelAndView(StatisMapping.SHOW_CUSTOMER_STATIS);
		return view;
	}
	
	/**
	 * 查询用户统计(折线图)
	 * @return
	 * @author xiaoky
	 */
	@RequestMapping(value = StatisMapping.QUERY_CUSTOMER_STATIS_DIFFLINE)
	@ResponseBody
	public RestResponse queryCustomerStatisDiffline (String type) {
		Map<String, Object> map = statisService.queryCustomerStatisDiffline(type);
		return GetRest.getSuccess("SUCCESS", map);
	}
	
	/**
	 * 查询用户统计(饼状图)
	 * @return
	 * @author xiaoky
	 */
	@RequestMapping(value = StatisMapping.QUERY_CUSTOMER_STATIS_PIE)
	@ResponseBody
	public RestResponse queryCustomerStatisPie () {
		List<Map<String, Object>> list = statisService.getCustomerFormPieData();
		return GetRest.getSuccess("", list);
	}
	
	/**
	 * 查询贡献值和共享值统计
	 * @return 贡献值和共享值数据
	 * @author xiaoky
	 */
	@RequestMapping(value = StatisMapping.QUERY_ACCOUNT_STATIS)
	@ResponseBody
	public RestResponse queryAccountStatis() {
		Map<String, Object> map = statisService.queryAccountStatis();
		return GetRest.getSuccess("", map);
	}
	
	/**
	 * 订单、退款数量统计页面
	 * @return
	 * @author xiaoky
	 */
	@RequestMapping(value = StatisMapping.SHOW_REFUND_NUM_STATIS)
	public ModelAndView showRefundNumStatis () {
		ModelAndView view = new ModelAndView(StatisMapping.SHOW_REFUND_NUM_STATIS);
		return view;
	}
	
	/**
	 * 订单&退款数量数据
	 * @param type 类型——day,work,month
	 * @return
	 */
	@RequestMapping(value = StatisMapping.QUERY_REFUND_NUM_STATIS)
	@ResponseBody
	public RestResponse queryRefundNumStatis (String type) {
		Map<String, Object> map = statisService.queryRefundNumStatis(type);
		return GetRest.getSuccess("SUCCESS", map);
	}
	
	/**
	 * 产品销量统计页面
	 * @return 
	 * @author xiaoky
	 */
	@RequestMapping(value = StatisMapping.SHOW_PRO_SALE_STATIS)
	public ModelAndView showProSaleStatis () {
		ModelAndView view = new ModelAndView(StatisMapping.SHOW_PRO_SALE_STATIS);
		return view;
	}
	
	/**
	 * 查询本月产品销量统计数据(前十)
	 * @param date 时间(null, 默认先查本月的, 如果有需要根据月份查询, 就在前端页面传值)
	 * @return
	 * @author xiaoky
	 */
	@RequestMapping(value = StatisMapping.QUERY_PRO_SALE_STATIS)
	@ResponseBody
	public RestResponse queryProSaleStatis (String date) {
		List<Map<String, Object>> list = statisService.queryProSaleStatis(date);
		return GetRest.getSuccess("SUCCESS", list);
	}


	/**
	 * 查询每天的用户统计(页面)
	 * @return
	 */
	@RequestMapping(value = StatisMapping.SHOW_EVERYDAY_CUSTOMER_STATIS)
	public ModelAndView showCustomerEveryDayStatis () {
		ModelAndView view = new ModelAndView(StatisMapping.SHOW_EVERYDAY_CUSTOMER_STATIS);
		return view;
	}


	/**
	 * 订单&退款数量数据
	 * @param type 类型——day,work,month
	 * @return
	 */
	@RequestMapping(value = StatisMapping.QUERY_ORDER_NUM_STATIS)
	@ResponseBody
	public RestResponse querOrderNumStatis (String type) {
		Map<String, Object> map = statisService.queryOrderNumStatis(type);
		return GetRest.getSuccess("SUCCESS", map);
	}
}
